{extend name="admin/base" /}
{block name="resources"/}
<style>
.mytable {border: 0;}
.style0list tbody td {vertical-align: middle;}
.style0list  tbody tr {border-bottom: 1px dashed  #E3E3E3;}
a{
	cursor:pointer;
}
</style>
{/block}
{block name="right_tab"} 
<li><a class="nscs-table-handle_green" href="{:__URL('ADMIN_MAIN/Member/addsupplier')}"><i class="fa fa-plus-circle"></i>&nbsp;添加供货商</a></li>
{/block}
{block name="main"}
<div class="mod-table">
	<div class="mod-table-head">
		<table class="mytable">
			<tr>
				<th width="10%" style="text-align: left;">
					<a class="btn btn-small fun-a" href="javascript:batchDelete()">批量删除</a>
				</th>
				<th width="20%">
					<input type="text" id = 'search_text' placeholder="输入代理商名称" />
					<input type="button" onclick="LoadingInfo(1)" value="搜索" />
				</th>
			</tr>
		</table>
		<div class="style0list">
			<table>
				<thead>
					<tr align="center">
						<th><label style="margin-left: 5px;"><input type="checkbox" onclick="CheckAll(this)"></label></th>
						<th class="tal">供货商名称</th>
						<th class="tal">联系人</th>
						<th class="tal">联系电话</th>
						<th class="tal">联系地址</th>
						<th class="tal">供货商描述</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody></tbody>
			</table>
		</div>
	</div>
</div>
{/block}
{block name="script"}

{include file="admin/pageCommon"/}
<script type="text/javascript">
	function LoadingInfo(page_index) {
		var search_text = $("#search_text").val();
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/Member/supplierList')}",
			async : true,
			data : {
				"page_index" : page_index, "page_size" :  $("#showNumber").val(), 'search_text' : search_text
			},
			success : function(data) {
				var html = '';
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						html += '<tr align="center">';
						html += '<td><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data["data"][i]["supplier_id"]+'" ></label></div></td>';
						html += '<td class="tal">'+ data["data"][i]["supplier_name"]+'</td>';	
						html += '<td class="tal">'+ data["data"][i]["linkman_name"]+'</td>';	
						html += '<td class="tal">'+ data["data"][i]["linkman_tel"]+'</td>';	
						html += '<td class="tal">'+ data["data"][i]["linkman_address"]+'</td>';	
						html += '<td class="tal">' + data['data'][i]['desc'] + '</td>';
						html += '<td> <a href="'+__URL('ADMIN_MAIN/Member/updatesupplier?supplier_id='+ data['data'][i]['supplier_id'])+'">修改</a>';
						html += '&nbsp;&nbsp;&nbsp;<a href="javascript:deleteSupplier('+data['data'][i]['supplier_id']+');">删除</a></td>';
						html += '</tr>';
					}
				} else {
					html += '<tr align="center"><th colspan="7">暂无符合条件的数据记录</th></tr>';
				}
				$(".style0list tbody").html(html);
				initPageData(data["page_count"],data['data'].length,data['total_count']);
				$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
				//load();
			}
		});
	}
	//全选
	function CheckAll(event){
		var checked = event.checked;
		$(".style0list tbody input[type = 'checkbox']").prop("checked",checked);
	}
	
	function deleteSupplier(supplier_id){
		$( "#dialog" ).dialog({
			buttons: {
				"确定": function() {
					$.ajax({
						type : "post",
						url : "{:__URL('ADMIN_MAIN/member/deleteSupplier')}",
						data : {
							'supplier_id' : supplier_id.toString()
						},
						async : true,
						success : function(data) {
							if (data['code'] > 0) {
								    showMessage('success', data["message"], "{:__URL('ADMIN_MAIN/member/supplierlist')}");
							} else if(data['code'] == -1){
									showMessage('error', '当前供货商存在供货商品，不能被删除！');
							}else{
								showMessage('error', data['message']);
							}
						}
					});
					$(this).dialog('close');
				},
				"取消,#e57373": function() {
					$(this).dialog('close');
				},
			},
			contentText:"确定要删除该供货商吗？",
		});
	}
	//批量删除
	function batchDelete() {
		var uid= new Array();
		$(".style0list input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				uid.push($(this).val());
			}
		});
		if(uid.length ==0){
			$( "#dialog" ).dialog({
				buttons: {
					"确定,#e57373": function() {
						$(this).dialog('close');
					}
				},
				contentText:"请选择需要操作的记录",
				title:"消息提醒",
			});
			return false;
		}
		deleteSupplier(uid);
	}
</script>
{/block}